//
//  CRHeaderCell.m
//  NewAge
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 ColorRevolution. All rights reserved.
//

#import "CRHeaderCell.h"
#import "CRNewsModel.h"

@implementation CRHeaderCell


#pragma mark - init

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}



#pragma mark - createCell

- (void)createCell {
    [self.contentView addSubview:self.picView];
    [self.picView addSubview:self.titleBgLabel];
    [self.picView addSubview:self.titleLabel];
    [self.contentView addSubview:self.pageLabel];
}



#pragma mark - lazyLoad

- (UIImageView *)picView {
    if (!_picView) {
        self.picView = [[UIImageView alloc] init];
    }
    return _picView;
}

- (UILabel *)titleBgLabel {
    if (!_titleBgLabel) {
        self.titleBgLabel = [[UILabel alloc] init];
        _titleBgLabel.backgroundColor = [UIColor blackColor];
        _titleBgLabel.alpha = 0.7;
    }
    return _titleBgLabel;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)pageLabel {
    if (!_pageLabel) {
        self.pageLabel = [[UILabel alloc] init];
        _pageLabel.textColor = [UIColor whiteColor];
        _pageLabel.font = [UIFont systemFontOfSize:13];
    }
    return _pageLabel;
}



#pragma mark - SetterMethod

- (void)setNews:(CRNewsModel *)news {
    if (_news != news) {
        _news = news;
        [self changeValue];
    }
}

- (void)changeValue {
    [_picView sd_setImageWithURL:[NSURL URLWithString:_news.imgsrc] placeholderImage:nil];
    _titleLabel.text = _news.title;
}



#pragma mark - setLayout

- (void)layoutSubviews {
    [_picView mas_makeConstraints:^(MASConstraintMaker *make) {
        EDGES(self.contentView, 0, 0, 0, 0);
    }];
    
    [_titleBgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(_picView, 0);
        Right(_picView, 0);
        Bottom(_picView, 0);
        HequalNum(30);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(_titleBgLabel.mas_top, 0);
        Left(_titleBgLabel.mas_left, 5 * WIDTH / 375.0);
        Bottom(_titleBgLabel.mas_bottom, 0);
        WequalNum(300 * WIDTH / 375.0);
    }];
    
    [_pageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(_titleBgLabel.mas_top, 0);
        Left(_titleLabel.mas_right, 0);
        Right(_titleBgLabel.mas_right, 0);
        Bottom(_titleBgLabel.mas_bottom, 0);
    }];
}

@end
